app.controller('checkLogininfo',function ($scope,$interval, $http, loginService,validateCodeService) {

//
// ['$scope', 'loginService','validateCodeService',
//     function ($scope, loginService,validateCodeService) {
    $scope.usernamevalue = '用户名';
    $scope.passwordvalue = '密码';
    $scope.buttonenable = false;

    $scope.enterEvent = function (e) {
        var keycode = window.event ? e.keyCode : e.which;
        var loginbutton = angular.element("#loginbutton")[0];
        if (keycode == 13 && !loginbutton.disabled) {
            $scope.login();
        }
    }

    $scope.vcodesrc = "";

    $scope.login = function () {
        $scope.buttonenable = true;

        if (!$scope.username) {
            $scope.buttonenable = false;
            promptMsg("用户名不能为空！");
            return;
        }
        if (!$scope.password) {
            $scope.buttonenable = false;
            promptMsg("密码不能为空！");
            return;
        }

        if (!$scope.verifycode) {
            $scope.buttonenable = false;
            promptMsg("验证码不能为空！");
            return;
        }

        if ($scope.username && $scope.password) { //如果用户和用户名及密码都是正确的
            var baseusername = window.btoa($scope.username);
            var basepassword = window.btoa($scope.password);
            loginService.userlogin({
                    username: baseusername,
                    password: basepassword,
                    verifycode:$scope.verifycode
                }, function (data) {
                    if (data.status == "SUCCESS") {
                        window.location.href = "/index";
                    } else {
                        promptMsg(data.errorReason);
                        document.getElementById("verifyimg").src = "/verifycode?d="+Math.random();
                    }
                    $scope.buttonenable = false;
                },
                function (error) {
                    $scope.buttonenable = false;
                    $scope.requestError(error);
                    promptMsg(error.data.msg);
                    //清空验证码
                    $scope.verifycode = "";
                    document.getElementById("verifyimg").src = "/verifycode?d="+Math.random();
                }
            );
        }
    };
    /**
     * 错误信息
     */
    $scope.requestError = function (error) {
        $scope.errorMessage = "unknown error!";
    };
});